package com.niodata.dp.monitor.sharelib.entity.base;

import com.niodata.dp.monitor.common.util.ThrowableUtil;
import java.util.List;

/**
 * Created by ndp on 17-7-14.
 */
public class MonitorResult<T> extends BaseResult<T> {

  private int pageIndex;
  private int start;
  private int stop;
  private boolean hasMore;

  public int getPageIndex() {
    return pageIndex;
  }

  public void setPageIndex(int pageIndex) {
    this.pageIndex = pageIndex;
  }

  public int getStart() {
    return start;
  }

  public void setStart(int start) {
    this.start = start;
  }

  public int getStop() {
    return stop;
  }

  public void setStop(int stop) {
    this.stop = stop;
  }

  public boolean isHasMore() {
    return hasMore;
  }

  public void setHasMore(boolean hasMore) {
    this.hasMore = hasMore;
  }

  @Override
  public MonitorResult<T> buildErrorResult(Throwable t) {
    this.setSuccess(false);
    this.setErrorMsg(t.getMessage());
    this.setErrorDetail(ThrowableUtil.getErrorDetailFromThrowable(t));
    this.setTimestamp(System.currentTimeMillis());
    return this;
  }

  @Override
  public MonitorResult<T> buildSuccessResult(List<T> dataList, boolean success) {
    this.setSuccess(success);
    if (dataList != null) {
      this.setData(dataList);
    }
    this.setTimestamp(System.currentTimeMillis());
    return this;
  }

  @Override
  public MonitorResult<T> buildSuccessResult(boolean success) {
    return this.buildSuccessResult(null, success);
  }
}
